package main;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import javax.swing.JScrollPane;

public class AISCanvasScrollPane extends JScrollPane {
	
	private AISCanvasPanel canvasPanel; 
	
	public AISCanvasScrollPane(){
		super(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		setBackground(new Color(0));
	}

	public void setImage(String arg0){
		canvasPanel = new AISCanvasPanel(arg0);
		setViewportView(canvasPanel);
	}
	
	public void paintComponent(Graphics g){
		g.setColor(new Color(0));
		g.fillRect(0, 0, canvasPanel.getWidth(), canvasPanel.getHeight());
	}
	
	public AISCanvasPanel getImagePanel(){
		return canvasPanel;
	}
	
	public void moveViewport(Point p){
		p.x -= (getViewport().getWidth() >> 1);
		p.y -= (getViewport().getHeight() >> 1);
		p.x = Math.max(0, p.x);
		p.y = Math.max(0, p.y);
		getViewport().setViewPosition(p);
		updateUI();
	}
}
